<div class="step1">
    <div class="important">
        请先转账成功后再点“下一步”按钮提交存款信息！
    </div>

    <table class="center-table-form">
        <tr>
            <td class="label">存款金额：</td>
            <td class="field">
                <input type="number" name="amount" placeholder="输入存款金额，单位：元" 
                        class="am-form-field" required/>
            </td>
            <td class="clue2">
                * 单笔下限<span class="red min">0</span>，单笔上限<span class="red max">0</span>
            </td>
        </tr>

        <tr>
            <td class="label">银行种类：</td>
            <td class="field">
                <select data-am-selected class="am-form-field banklist">
                </select>
            </td>
            <td class="clue2">
            </td>
        </tr>
        <tr>
            <td class="label">开户网点：</td>
            <td class="field">
                <input type="text" name="bank_addr" class="am-form-field" disabled/>
            </td>
            <td class="clue2">
            </td>
        </tr>
        <tr>
            <td class="label">开户姓名：</td>
            <td class="field">
                <input type="text" name="bank_name" class="am-form-field" disabled/>
            </td>
            <td class="clue2">
            </td>
        </tr>
        <tr>
            <td class="label">银行卡号：</td>
            <td class="field">
                <input type="text" name="bank_account" class="am-form-field" disabled/>
            </td>
            <td class="clue2">
            </td>
        </tr>

        <tr>
            <td class="label">转账人：</td>
            <td class="field">
                <input type="text" name="sender" class="am-form-field" placeholder="请填写实际转账人姓名" />
            </td>
            <td class="clue2">
            </td>
        </tr>

        <tr>
            <td class="label">转账时间：</td>
            <td class="field">
                <input type="text" name="time" class="am-form-field" placeholder="" data-am-datepicker readonly />
            </td>
            <td class="clue2">
            </td>
        </tr>
    </table>
</div>

<div class="step2">
    <div class="important">
        <img src="../public/all/images/important.png" width="18px"/>
        为了加快入款速度，请务必于转账后再提交资料！
    </div>

    <div class="charge-title">存款信息</div>
    <div class="charge_info">
        <div class="c c1">存入金额：<span class="red">0.00</span></div>
        <div class="c c2">用户姓名：<span></span></div>
        <div class="c c3">存款时间：<span></span></div>
        <div class="c c4">存款方式：<span>银行转账</span></div>
    </div>
    <div class="charge-title">银行信息</div>
    <div class="bank_info">
        <div class="c c1">开户银行：<span></span></div>
        <div class="c c2">开户网点：<span></span></div>
        <div class="c c3">开户姓名：<span></span></div>
        <div class="c c4">银行卡号：<span></span></div>
    </div>
</div>

<script>
    $(function() {
        $("input[name='time']").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss"
        });
        $("input[name='time']").val(new Date().Format("yyyy-MM-dd HH:mm:ss"));
    });
    $(".step2").hide();
    $(".charge-c .img img").attr("src", "../public/all/images/charge_step_bank.jpg");

    var currStep = 1;
    var banks = [];
    ME.query(function() {
        Classify.queryExt("money", "banks", true, [], function(r) {
            var grade = context.user.user.grade || 1;
            grade = grade + '';
            for (var i in r) {
                if (r[i].enable != 1) continue;
                if (r[i].layer.indexOf(grade) == -1) continue;
                banks.push(r[i]);
            }
            
            // 填充银行列表
            var list = $("select.banklist");
            list.empty();
            for (var i in banks) {
                var bank = banks[i];
                if (!bank.enable) continue;
                list.append('<option value="' + bank.bank + '">' + bank.bank + '</option>');
            }
            fillBankInfo();
        });
    });

    function fillBankInfo() {
        var b = $("select.banklist").val();
        var bank;
        for (var i in banks) {
            if (banks[i].bank == b) {
                bank = banks[i];
                break;
            }
        }
        if (!bank) return;
        $("input[name='bank_addr']").val(bank.addr || '');
        $("input[name='bank_name']").val(bank.name || '');
        $("input[name='bank_account']").val(bank.account || '');

        $("span.min").html(bank.min || 0);
        $("span.max").html(bank.max || 0);
    }
    $("select.banklist").change(fillBankInfo);

    $(".btn-next").click(function() {
        if (currStep == 1) {
            var amount = $("input[name='amount']").val().trim();
            if (amount == '' || parseInt(amount) < parseInt($("span.min").html()) || 
                parseInt(amount) > parseInt($("span.max").html())) {
                alert2("存款金额不对！", true);
                return;
            }

            var name = $("input[name='sender']").val().trim();
            if (name == '') {
                alert2("请填写转账人的姓名！", true);
                return;
            }

            var b = $("select.banklist").val();
            var bank;
            for (var i in banks) {
                if (banks[i].bank == b) {
                    bank = banks[i];
                    break;
                }
            }
            if (!bank) return;

            // 确认信息
            currStep = 2;
            $(".btn-next").html("提交申请");
            $(".step1").hide();
            $(".step2").show();

            $(".step2 .charge_info .c1 span").html(amount);
            $(".step2 .charge_info .c2 span").html(name);
            $(".step2 .charge_info .c3 span").html($("input[name='time']").val());
            $(".step2 .bank_info .c1 span").html(bank.bank);
            $(".step2 .bank_info .c2 span").html(bank.addr);
            $(".step2 .bank_info .c3 span").html(bank.name);
            $(".step2 .bank_info .c4 span").html(bank.account);
        }
        else {
            // 提交信息
            var amount = $("input[name='amount']").val().trim();
            var name = $("input[name='sender']").val().trim();
            var time = $("input[name='time']").val();
            var memo = "转账人：" + name + "<br/>";

            var b = $("select.banklist").val();
            var bank;
            for (var i in banks) {
                if (banks[i].bank == b) {
                    bank = banks[i];
                    break;
                }
            }

            memo += "银行：" + bank.bank + "<br/>";
            memo += "收款人：" + bank.name + "<br/>";
            memo += "银行账号：" + bank.account;

            startLoading();
            CMD.deposit(null, "", amount * 100, "handOper", "bank", memo, function() {
                stopLoading();
                alert2("提交请求成功！");
            })
        }
    });
</script>